<?php

namespace app\data\command;

use app\data\model\DataWechat;
use think\admin\Command;
use think\admin\Exception;
use think\console\Input;
use think\console\Output;
use think\Model;

/**
 * 每月月初更改渠道用户结算状态
 * Class SettleAccounts
 * @package app\data\command
 */
class UpdateChannelStutas extends Command
{
    protected function configure()
    {
        $this->setName('xdata:UpdateChannelStutas');
        $this->setDescription('每月月初更改渠道用户结算状态');
    }

    /**
     * 业务指令执行
     * @param Input $input
     * @param Output $output
     * @return void
     * @throws Exception
     */
    protected function execute(Input $input, Output $output)
    {
        $this->_autoUpdateDistribution();
    }
    /**
     * 重置状态  便于七号结算佣金
     * @throws Exception
     */
    private function _autoUpdateDistribution()
    {
        try {
            $date = \Tools::getDateTimeByTime('d',time());
            if($date != '1'){
                return true;
            }
            DataWechat::mk()->update(array(
                'status'    => 0,
                'updated_at'    => \Tools::getDateTimeByTime()
            ),[['id','>',0]]);
        } catch (\Exception $exception) {
            $this->queue->error($exception->getMessage());
        }
    }
}
